<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\index\logic;


/**
 * Index基础逻辑
 */
class Payment extends IndexBase
{
	public function wxpay(){
		$order=array();
		$res=$this->servicePay->driverWxpay->pay($order,'h5',2);
		return $res;
	}
	public function zfbnotify(){
		$res=$this->servicePay->driverAlipay->notify();
		if($res){
			$str=substr($_POST['out_trade_no'],0,2);
			if($str == 'gs'){
				$stat=db('order_goods')->where('order_sn',$_POST['out_trade_no'])->value('stat');
				if($stat != 1){
					db('order_goods')->where('order_sn',$_POST['out_trade_no'])->update(['stat'=>1,'zf_time'=>date('Y-m-d H:i:s')]);
					db('order_info')->where(['order_sn'=>$_POST['out_trade_no'],'catid'=>1])->update(['stat'=>1,'fh_time'=>date('Y-m-d H:i:s')]);
				}
			}elseif($str == 'xx'){
				$ginfo=db('order')->where('order_sn',$_POST['out_trade_no'])->find();
				if($ginfo['stat'] != 1){
					$tjid=db('user')->where('id',$ginfo['user_id'])->value('tjid');
					$dinfo=db('dian')->field('bl,btbl,lrbl,city,county')->where('user_id',$ginfo['getid'])->find();
					db('order')->where('order_sn',$_POST['out_trade_no'])->update(['stat'=>1,'zf_time'=>date('Y-m-d H:i:s')]);
					fenrun($ginfo['user_id'],$ginfo['getid'],$ginfo['money'],$dinfo['lrbl'],$dinfo['btbl'],$dinfo['bl'],$dinfo['city'],$dinfo['county'],$tjid);
				}
			}
		}
	}
	public function wxNotify(){
		$res=$this->servicePay->driverWxpay->notify();
		if($res){
			$xmlData = file_get_contents('php://input');
			$data = json_decode(json_encode(simplexml_load_string($xmlData, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
			$str=substr($data['out_trade_no'],0,2);
			if($str == 'gs'){
				$stat=db('order_goods')->where('order_sn',$data['out_trade_no'])->value('stat');
				if($stat != 1){
					db('order_goods')->where('order_sn',$data['out_trade_no'])->update(array('stat'=>1,'zf_time'=>date('Y-m-d H:i:s')));
				}
			}

		}
	}
}
